﻿using Dapper;
using System.Data.SqlClient;
using yunbo.Model.RMM;

namespace yunbo.Repositorys.RMMRepositorys
{
    public class AttachmentRepository
    {
        public string data = "Data Source=121.37.93.71;Initial Catalog=FanXingMES;User ID=sa;Password=geili@2025;";

        public async Task<int> SaveAttachmentToDb(Attachment attachment)
        {
            using (SqlConnection connection = new SqlConnection(data))
            {
                string sql = $@"insert into [dbo].[attachments](yclcg_code, attachments_lx, attachments_url, create_by, create_time)
                                values('{attachment.yclcg_code}','{attachment.attachments_lx}','{attachment.attachments_url}','{attachment.create_by}','{attachment.create_time}')";

                try
                {
                    return await connection.ExecuteScalarAsync<int>(sql, attachment);
                }
                catch (SqlException ex)
                {
                    // 记录日志
                    Console.WriteLine($"SQL Error: {ex.Message}");
                    throw;
                }
                
            }
        }
    }
}
